package com.itheima.test2;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/*

服务器：收到消息后给出反馈
 */
public class ServerDemo {

    public static void main(String[] args) throws IOException {
        //创建服务端对象
        ServerSocket ss = new ServerSocket(8858);

        //建立连接
        Socket accept = ss.accept();
        //获取输入流
        InputStream is = accept.getInputStream();
        //读数据
        int len;
        byte[] bytes= new byte[1024];
        while ((len=is.read(bytes))!=-1){
            String s = new String(bytes, 0, len);
            System.out.println(s);
        }
        //给出反馈
        //获取输出流
        OutputStream os = accept.getOutputStream();
        //写数据
        os.write("你好".getBytes());

        //释放资源
       // accept.shutdownOutput();
        os.close();
        ss.close();
    }
}
